/* eslint-disable */
/**
 * 初始化一些服务内容
 */
import VConsole from 'vconsole'
import device from './device'
import Vue from 'vue'
import store from '@/store'
import { getUrlParams} from '@/util/base'
import $newsdk from "../native/newsdk";

// import
// setupWebViewJavascriptBridge
// from "@/native/callApp";

export const init = async (configs, success) => {
  // 平台
  window.APP_PLATFORM = device.os
  window.isIphoneX = device.iphoneX
  let device_info = {
    deviceType: device.os,
    isIphonex: device.iphoneX
  }


  // store.commit('setDevice', device_info)

  // 如果需要VConsole
  if (configs.needVconsole) {
    /* eslint-disable no-new */
    // let vConsole = new VConsole()
    // Vue.use(vConsole)
  }
  console.log('window.APP_PLATFORM', window.APP_PLATFORM);
  const urlParams = getUrlParams();
  if (urlParams.outlink && urlParams.outlink == 1) {
    return success()
  }
  // if (window.location.href.includes("cardInfo")) {
  //   return success()
  // };
  // if (window.location.href.includes("giftId")) {
  //   return success()
  // };
  // if (window.location.href.includes("orgId")) {
  //   return success()
  // };
  // if (window.location.href.includes("type")) {
  //   return success()
  // };
  // if (window.location.href.includes("birthSign")) {
  //   return success()
  // };
  // if (window.location.href.includes("FestivalCard")) {
  //   return success()
  // };
  // if (window.location.href.includes("BirthDayScreen")) {
  //   return success()
  // };
  try {
    console.log(33333, "beta:2020/11/7")
    //从原生获取用户token
    // $newsdk.$getToken().then((res) => {
    //   sessionStorage.setItem("tokenX", res.data);
    //   console.log(`获取到的token: ${res.data}`);
    //   success();
    // });
    // console.log(222)
    // $newsdk.$getUserInfo().then((res) => {
    //   sessionStorage.setItem("userInfo", res.data);
    //   console.log("getUserInfo:"+res.data);
    //   success();
    // });
    //从原生获取用户token
    const res = await $newsdk.$getToken();
    // console.log(4444)
    sessionStorage.setItem("tokenX", res.data);
    console.log(`获取到的token: ${res.data}`);
    console.log("token的json:" + JSON.stringify(res.data))
    const userInfo = await $newsdk.$getUserInfo();
    sessionStorage.setItem("userId", userInfo.data.userId);
    sessionStorage.setItem("organId", userInfo.data.companyId); //企业id
    sessionStorage.setItem("organName", userInfo.data.organName); //企业名字
    sessionStorage.setItem("avatar", userInfo.data.avatar); //企业logo
    sessionStorage.setItem("opneId", userInfo.data);
    sessionStorage.setItem("userName", userInfo.data.userName);
    console.log("userInfo的json:" + JSON.stringify(res.data))
    // console.log(3333)
    success();
  } catch (error) {
    console.log(444)
    success();
  }
  // } catch (error) {
  //   success();
  // }
}
